clear all
set more off


use Table1

gen quan=_n

*GQR
gen meanbias1=.
gen MAD1=.
gen rmse1=.
gen reject1_05=.
foreach num of numlist 5(5)95 {
	sum RRR`num'5
	replace meanbias1=r(mean)-`num'/100 if quan==`num'
	gen absdev=abs(RRR`num'5-`num'/100)
	egen tmp=median(absdev)
	replace MAD1=tmp if quan==`num'
	drop absdev tmp
	gen dev=(RRR`num'5-`num'/100)^2
	egen tmp=mean(dev)
	replace rmse1=tmp^.5 if quan==`num'
	drop dev tmp
	

}

*DR1
gen meanbias2=.
gen MAD2=.
gen rmse2=.
foreach num of numlist 5(5)95 {
	sum RRR`num'1
	replace meanbias2=r(mean)-`num'/100 if quan==`num'
	gen absdev=abs(RRR`num'1-`num'/100)
	egen tmp=median(absdev)
	replace MAD2=tmp if quan==`num'
	drop absdev tmp
	gen dev=(RRR`num'1-`num'/100)^2
	egen tmp=mean(dev)
	replace rmse2=tmp^.5 if quan==`num'
	drop dev tmp
}
	
*DR2
gen meanbias3=.
gen MAD3=.
gen rmse3=.
foreach num of numlist 5(5)95 {
	sum RRR`num'2
	replace meanbias3=r(mean)-`num'/100 if quan==`num'
	gen absdev=abs(RRR`num'2-`num'/100)
	egen tmp=median(absdev)
	replace MAD3=tmp if quan==`num'
	drop absdev tmp
	gen dev=(RRR`num'2-`num'/100)^2
	egen tmp=mean(dev)
	replace rmse3=tmp^.5 if quan==`num'
	drop dev tmp
}
	
*QR1
gen meanbias4=.
gen MAD4=.
gen rmse4=.
foreach num of numlist 5(5)95 {
	sum RRR`num'6
	replace meanbias4=r(mean)-`num'/100 if quan==`num'
	gen absdev=abs(RRR`num'6-`num'/100)
	egen tmp=median(absdev)
	replace MAD4=tmp if quan==`num'
	drop absdev tmp
	gen dev=(RRR`num'6-`num'/100)^2
	egen tmp=mean(dev)
	replace rmse4=tmp^.5 if quan==`num'
	drop dev tmp
}

*QR2
gen meanbias5=.
gen MAD5=.
gen rmse5=.
foreach num of numlist 5(5)95 {
	sum RRR`num'7
	replace meanbias5=r(mean)-`num'/100 if quan==`num'
	gen absdev=abs(RRR`num'7-`num'/100)
	egen tmp=median(absdev)
	replace MAD5=tmp if quan==`num'
	drop absdev tmp
	gen dev=(RRR`num'7-`num'/100)^2
	egen tmp=mean(dev)
	replace rmse5=tmp^.5 if quan==`num'
	drop dev tmp
}
	
keep if meanbias1<.
keep meanb* rmse* MAD* quan
export excel Table1results, replace

clear

use Table2

gen quan=_n

*GQR
gen meanbias1=.
gen MAD1=.
gen rmse1=.
gen reject1_05=.
foreach num of numlist 5(5)95 {
	sum RRR`num'3
	replace meanbias1=r(mean)-`num'/100 if quan==`num'
	gen absdev=abs(RRR`num'3-`num'/100)
	egen tmp=median(absdev)
	replace MAD1=tmp if quan==`num'
	drop absdev tmp
	gen dev=(RRR`num'3-`num'/100)^2
	egen tmp=mean(dev)
	replace rmse1=tmp^.5 if quan==`num'
	drop dev tmp
	

}

*DR1
gen meanbias2=.
gen MAD2=.
gen rmse2=.
foreach num of numlist 5(5)95 {
	sum RRR`num'1
	replace meanbias2=r(mean)-`num'/100 if quan==`num'
	gen absdev=abs(RRR`num'1-`num'/100)
	egen tmp=median(absdev)
	replace MAD2=tmp if quan==`num'
	drop absdev tmp
	gen dev=(RRR`num'1-`num'/100)^2
	egen tmp=mean(dev)
	replace rmse2=tmp^.5 if quan==`num'
	drop dev tmp
}
	
*DR2
gen meanbias3=.
gen MAD3=.
gen rmse3=.
foreach num of numlist 5(5)95 {
	sum RRR`num'2
	replace meanbias3=r(mean)-`num'/100 if quan==`num'
	gen absdev=abs(RRR`num'2-`num'/100)
	egen tmp=median(absdev)
	replace MAD3=tmp if quan==`num'
	drop absdev tmp
	gen dev=(RRR`num'2-`num'/100)^2
	egen tmp=mean(dev)
	replace rmse3=tmp^.5 if quan==`num'
	drop dev tmp
}
	
*QR1
gen meanbias4=.
gen MAD4=.
gen rmse4=.
foreach num of numlist 5(5)95 {
	sum RRR`num'4
	replace meanbias4=r(mean)-`num'/100 if quan==`num'
	gen absdev=abs(RRR`num'4-`num'/100)
	egen tmp=median(absdev)
	replace MAD4=tmp if quan==`num'
	drop absdev tmp
	gen dev=(RRR`num'4-`num'/100)^2
	egen tmp=mean(dev)
	replace rmse4=tmp^.5 if quan==`num'
	drop dev tmp
}

*QR2
gen meanbias5=.
gen MAD5=.
gen rmse5=.
foreach num of numlist 5(5)95 {
	sum RRR`num'5
	replace meanbias5=r(mean)-`num'/100 if quan==`num'
	gen absdev=abs(RRR`num'5-`num'/100)
	egen tmp=median(absdev)
	replace MAD5=tmp if quan==`num'
	drop absdev tmp
	gen dev=(RRR`num'5-`num'/100)^2
	egen tmp=mean(dev)
	replace rmse5=tmp^.5 if quan==`num'
	drop dev tmp
}
	
keep if meanbias1<.
keep meanb* rmse* MAD* quan
export excel Table2results, replace


